/*
 * AbstractItem.java
 *
 * Created on 26. Dezember 2006, 14:56
 *
 * Copyright (c) 2007 Daniel Gronau
 *
 * This file is part of KanjiTori.
 *
 * KanjiTori is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * KanjiTori is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */

package kanjitori.graphics.item;

import com.jme.bounding.BoundingBox;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.shape.RoundedBox;
import com.jme.scene.state.CullState;
import kanjitori.graphics.AbstractThing;
import kanjitori.graphics.item.Item;
import kanjitori.events.ItemCollectedEvent;
import kanjitori.events.ManagerService;
import kanjitori.util.GraphicUtil;

/**
 *
 * @author Pirx
 */
public abstract class AbstractItem extends AbstractThing implements Item {
    
    /** Creates a new instance of AbstractItem */
    public AbstractItem() {
    }
    
    public AbstractItem (String textureName) {
        RoundedBox box = new RoundedBox("box", 
                new Vector3f(0.2f, 0.2f, 0.2f), 
                new Vector3f(0.04f, 0.04f, 0.04f), 
                new Vector3f(0.02f, 0.02f, 0.02f));
        box.setRenderState(GraphicUtil.getMaterialState(new ColorRGBA(1, 1, 1, 1)));
        box.setRenderState(GraphicUtil.loadTexture(textureName, false));
        box.setRenderState(GraphicUtil.getCullState(CullState.CS_BACK));
        box.updateRenderState();
        box.setModelBound(new BoundingBox());
        box.updateModelBound();
        node = new Node("item");
        node.attachChild(box);    
    }    
    
    public void consume() {
        node.getParent().detachChild(node);
        ManagerService.fireEvent(new ItemCollectedEvent(this));
    }    
}
